package com.zxy.employee.controller;


import com.zxy.base.dto.Result;
import com.zxy.base.util.ResultUtil;
import com.zxy.employee.dto.EmployeeSchoolDto;
import com.zxy.employee.entity.EmployeeSchoolEntity;
import com.zxy.employee.service.EmployeeSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeSchoolController {


    @Autowired
    private EmployeeSchoolService employeeSchoolService;

    @GetMapping("/getEmployeeSchoolByEmployeeId")
    public Result getEmployeeSchoolByEmployeeId(Integer employeeId) {

        List<EmployeeSchoolEntity> employeeSchoolEntities = employeeSchoolService.selectEmployeeSchoolByEmployeeId(employeeId);

        return ResultUtil.success(employeeSchoolEntities);
    }

    @PostMapping("/saveEmploySchool")
    public Result saveEmploySchool(@RequestBody  EmployeeSchoolDto employeeSchoolDto) {

        List<EmployeeSchoolEntity> saveResult = employeeSchoolService.save(employeeSchoolDto.getEmployeeId(), employeeSchoolDto.getEmployeeSchoolList());

        return ResultUtil.success(saveResult);


    }
}
